﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _2021_6_24
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void signIn_Click(object sender, EventArgs e)
        {
            if (account.Text == "" || pass.Text == "")
            {
                Response.Write("账号或密码为空");
            }
            else
            {
                SqlParameter[] pars =
                {
                    new SqlParameter("@name",account.Text),
                    new SqlParameter("@pass",pass.Text),
                };

                //    SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123456;database=Student_db");
                //    con.Open();
                //    SqlCommand cmd = new SqlCommand("select * from StudentInfo where stu_name=@name and password=@pass", con);

                // SqlAssistant assistant = new SqlAssistant(serverAddress:"",database:"",uid:"",pwd:""); 以SQL身份验证模式连接

                SqlAssistant assistant = new SqlAssistant(database:"Student_db",serverAddress:".");//以windows身份验证模式连接

                if (assistant.Querty("select * from StudentInfo where stu_name=@name and password=@pass", pars).Rows.Count > 0)
                {
                    Session["account"] = account.Text;
                    Response.Redirect("Welcome.aspx");
                }
                else
                {
                    Response.Write("登入失败");
                }
            }

            //    cmd.Parameters.AddRange(pars);
            //    SqlDataReader reader = cmd.ExecuteReader();
            //    if (reader.Read())
            //    {
            //        Session["account"] = account.Text;
            //        Response.Redirect("Welcome.aspx");
            //    }
            //    else
            //    {
            //        Response.Write("登入失败");
            //    }


        }
    }
}